﻿using AbpEntityFrameworkcore.DbContext;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AbpEntityFrameworkcore.DbContextDesignFac
{
    public class MyDbContextDesignFac : IDesignTimeDbContextFactory<MyDbContext>
    {

        //string Lmsconnstr = Environment.GetEnvironmentVariable("常州贸联", EnvironmentVariableTarget.Machine);
        string Lmsconnstr = ConfigStaticHelper.GetDbConnect();
        public MyDbContext CreateDbContext(string[] args)
        {
  

            DbContextOptionsBuilder<MyDbContext> builder =
            new DbContextOptionsBuilder<MyDbContext>();
            builder.UseSqlServer(Lmsconnstr, sqlOptions =>
            {
                sqlOptions.CommandTimeout(3);
                //我设置了时间为1秒 可是还是会等待连接好一阵子

            });
            MyDbContext ctx = new MyDbContext(builder.Options);
            return ctx;
        }

    
    }
}
